import socket  

def test_udp_port(host='172.16.72.3', port=554, timeout=2):  
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  
    sock.settimeout(timeout)  # 设置超时时间  

    message = b'Ping'  
    try:  
        # 发送消息  
        sock.sendto(message, (host, port))  
        print(f"发送到 {host}:{port}: {message.decode()}")  

        # 尝试接收响应  
        data, _ = sock.recvfrom(1024)  
        print(f"收到来自 {host}:{port} 的响应: {data.decode()}")  

    except socket.timeout:  
        print(f"未收到来自 {host}:{port} 的响应，端口可能不通或未打开")  
    except Exception as e:  
        print(f"发生错误: {e}")  
    finally:  
        sock.close()  

if __name__ == "__main__":  
    test_udp_port()  # 默认测试127.0.0.1:12345